<template>
    <div>
        <div class="">
            <Form ref="addForm" :model="addForm" :rules="ruleValidate" :label-width="80">
                <FormItem label="收件人:" prop="recipient">
                    <Input type="text" clearable style="width: 240px" placeholder="请输入收件人" v-model="addForm.recipient"></Input>
                </FormItem>
                <FormItem label="主题:" prop="topic">
                    <Input type="text" clearable style="width: 240px" placeholder="请输入主题" v-model="addForm.topic" number></Input>
                </FormItem>
                <div style="width: 1000px;height: 500px;">
                    <Form-item label="正文" prop="body" style="height: 500px;">
                        <i-input v-model="addForm.body"  clearable type="textarea" placeholder="请输入..."></i-input>
                    </Form-item>
                </div>

                <div style="margin-left:80px;">
                    <Button type="primary" size="large" @click="saveForm('addForm')" class="margin-top-20">发送</Button>
                    <Button type="" size="large" @click="saveForm('addForm')" style="margin-left:60px;" class="margin-top-20">存草稿</Button>
                </div>
            </Form>
        </div>
    </div>
</template>


<script>
    import { sendMessageApi} from '../../http/message.api'
    export default {
        name: 'sendMessage',
        data () {
            return {
                spinShow: false,
                addForm: {
                    recipient: '',
                    topic: '',
                    body: ''
                },
                ruleValidate: {
                    recipient: [
                        { required: true, message: '收件人不能为空', trigger: 'blur' },
                        { max: 255, message: '最多输入255个字符', trigger: 'blur' }
                    ],
                    topic: [
                        { required: true, message: '主题不能为空', trigger: 'blur' },
                        { max: 255, message: '最多输入255个字符', trigger: 'blur' }
                    ],
                    body: [
                        { required: true, message: '正文不能为空', trigger: 'blur' },
                        { max: 255, message: '最多输入255个字符', trigger: 'blur' }
                    ]
                },
            }
        },
        watch: {

        },
        created () {

        },
        methods: {
            //保存
            saveForm (name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.spinShow = true
                        sendMessageApi(this.addForm).then(suc => {
                            /*this.addModal = false
                            this.$emit('emitAddPerSuc')
                            this.spinShow = false
                            this.$router.push('/role')
                            console.log("1")
                            this.getPerTable()
                            console.log("2")*/
                            this.$router.push({ path: '/Setting'})
                        }).catch(err => {
                            this.$Message.error("错误代码【"+err.data.code+"】，"+err.data.message)
                            this.spinShow = false
                        })
                    }
                })
            }
        }
    }
</script>


<style>
    textarea.ivu-input{
        min-height:400px;
    }
</style>